home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / LED.PAK / LED.CPP next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.4 KB  |  128 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1992 by Borland International
  3. // led.cpp - LedWindow Demo Program
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/window.h>
  7. #include <owl/dc.h>
  8. #include <owl/gdiobjec.h>
  9. #include <stdio.h>
  10. #include <time.h>
  11. #include <math.h>
  12.  
  13. #include "ledwind.h"
  14.  
  15. class TLedDemoWindow : public TFrameWindow {
  16.   public:
  17.     TLedDemoWindow(TWindow* parent, const char* title);
  18.     void Paint(TDC& dc, bool erase, TRect& rect);
  19.  
  20.   DECLARE_RESPONSE_TABLE(TLedDemoWindow);
  21. };
  22. DEFINE_RESPONSE_TABLE1(TLedDemoWindow, TWindow)
  23.   EV_WM_PAINT,
  24. END_RESPONSE_TABLE;
  25.  
  26. //
  27. //
  28. //
  29. TLedDemoWindow::TLedDemoWindow(TWindow* parent, const char* title)
  30. :
  31.   TFrameWindow(parent, title)
  32. {
  33.   Attr.X = 150;
  34.   Attr.Y = 150;
  35.   Attr.W = 250;
  36.   Attr.H = 195;
  37.   Attr.Style = WS_BORDER | WS_MINIMIZEBOX | WS_SYSMENU;
  38.   SetIcon(GetModule(), "LedICON");
  39.   SetBkgndColor(TColor::Sys3dFace);
  40. }
  41.  
  42. //
  43. // Label the Demo Leds
  44. //
  45. void TLedDemoWindow::Paint(TDC& dc, bool /*erase*/, TRect& /*rect*/)
  46. {
  47.   dc.SetBkMode(TRANSPARENT);
  48.   dc.TextOut(TPoint(160, 20), "Long Num.", 9);
  49.   dc.TextOut(TPoint(70, 60), "Seconds Timer", 13);
  50.   dc.TextOut(TPoint(135, 100), "Time of Day", 11);
  51.   dc.TextOut(TPoint(135, 140), "Internal Clock", 14);
  52. }
  53.  
  54. //----------------------------------------------------------------------------
  55.  
  56. //
  57. //
  58. //
  59. class TLedDemoApp : public TApplication {
  60.   public:
  61.     TLedDemoApp() : TApplication() {}
  62.  
  63.     void InitMainWindow();
  64.     void InitInstance();
  65.     bool IdleAction(long idleCount);
  66.  
  67.     TLedWindow* LargeLed;
  68.     TLedWindow* TimerLed;
  69.     TLedWindow* ClockLed;
  70.     TLedWindow* Clock2Led;
  71. };
  72.  
  73. //
  74. //
  75. //
  76. void TLedDemoApp::InitMainWindow()
  77. {
  78.   TFrameWindow* frame = new TLedDemoWindow(0, "Led Demo");
  79.   LargeLed = new TLedWindow(frame, 15, 15, 10, true, false, 1234567890l);
  80.   TimerLed = new TLedWindow(frame, 15, 55, 3, true, false, 0);
  81.   ClockLed = new TLedWindow(frame, 15, 95, 0, true, true, time(0));
  82.   Clock2Led = new TLedWindow(frame, 15, 135, 0, true, true, 3600);
  83.   SetMainWindow(frame);
  84. }
  85.  
  86. //
  87. //
  88. //
  89. void TLedDemoApp::InitInstance()
  90. {
  91.   // Start TimerLed Timer (timer must be associated with an HWindow,
  92.   // which does not exist before InitInstance MakeWindow call).
  93.   //
  94.   TApplication::InitInstance();     // perform usual init stuff
  95.   TimerLed->StartTimer(1);          // Update TimerLed every second
  96.   ClockLed->StartTimer(1);          // Update ClockLed every second
  97. }
  98.  
  99. //
  100. //
  101. //
  102. bool TLedDemoApp::IdleAction(long /*time*/)
  103. {
  104.   if (TimerLed->LedValue == 20) {   // 20 seconds after invoke
  105.     Clock2Led->StartTimer(1);       // Update Clock2Led every second
  106.     LargeLed->DisplayNumber(1111111111l); // Change LargeLed value
  107.   }
  108.   if (TimerLed->LedValue == 30) {   // 30 seconds after invoke
  109.     LargeLed->DisplayNumber(987654321l);  // Change LargeLed value
  110.   }
  111.   if (TimerLed->LedValue == 82) {   // 82 seconds after invoke
  112.     TimerLed->StopTimer();          // Stop TimerLed at 061
  113.     TimerLed->DisplayNumber(1999);  // Move 1999 to TimerLed
  114.                                     // (only 3 digits: 999 displayed)
  115.     Clock2Led->StopTimer();         // Stop Clock2Led at 01:01:01
  116.   }
  117.   return true;
  118. }
  119.  
  120. //
  121. //
  122. //
  123. int
  124. OwlMain(int /*argc*/, char* /*argv*/ [])
  125. {
  126.   return TLedDemoApp().Run();
  127. }
  128.